{  Statement: http://acmp.ru/?main=task&id_task=119
   Verdict: Accepted
}
uses
        SysUtils, Math;

var
    i,n,x,y,z:longint;
    a:array[0..110] of longint;

procedure sort(l,r:longint);

var
    i,j,x,y:longint;

begin
i:=l;
j:=r;
x := a[(l + r) shr 1];
repeat
    while a[i] < x do inc(i);
    while a[j] > x do dec(j);
    if i <= j then begin
        y := a[i];
        a[i] := a[j];
        a[j] := y;
        inc(i);
        dec(j);
    end;
until i > j;
if l < j then sort(l, j);
if i < r then sort(i, r);
end;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
for i:=1 to n do begin
    read(x,y,z);
    a[i] := x * 3600 + y * 60 + z;
end;
sort(1,n);
for i:=1 to n do
    writeln(a[i] div 3600,' ',(a[i] mod 3600) div 60,' ',a[i] mod 60);
end.
